package com.xyz.basesdk.utils;

import android.content.Context;
import android.support.annotation.StringRes;
import android.view.Gravity;
import android.widget.Toast;

import com.xyz.basesdk.base.BaseApplication;


/**
 * 作者：xy_z on 2016/5/4 11:01
 * 邮箱：xyz@163.com
 */
public class MyToast {
    private static Toast mToast;

    private MyToast() {
    }

    public static void showToast(Context context, String text) {

        if (mToast == null) {
            mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
            mToast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static void showToast(String text) {

        if (mToast == null) {
            mToast = Toast.makeText(BaseApplication.getContext(), text, Toast.LENGTH_SHORT);
            mToast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    public static void showToast(@StringRes int text) {
        if (mToast == null) {
            mToast = Toast.makeText(BaseApplication.getContext(), text, Toast.LENGTH_SHORT);
            mToast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            mToast.setText(text);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }


    public static void showLongToast(String str) {
        if (mToast == null) {
            mToast = Toast.makeText(BaseApplication.getContext(), str, Toast.LENGTH_LONG);
            mToast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            mToast.setText(str);
            mToast.setDuration(Toast.LENGTH_LONG);
        }
        mToast.show();
    }


    public void cancelToast() {
        if (mToast != null) {
            mToast.cancel();
        }
    }

}
